package dr.incomeapp.model;

import java.util.LinkedList;
import java.util.List;

import dr.incomeapp.bean.CategoryBean;
import dr.incomeapp.bean.IncomeBean;
import dr.incomeapp.dao.CategoryDao;
import dr.incomeapp.dao.FactoryDao;
import dr.incomeapp.dao.IncomeDao;

public class IncomeEditModel {

	protected boolean isNew = false;
	
	protected IncomeBean incomeBean = null;
	protected List<CategoryBean> listCategory;
	
	protected IncomeDao incomeDao = FactoryDao.getIncomeDao();
	
	protected CategoryDao categoryDao = FactoryDao.getCategoryDao();
	
	public IncomeEditModel(){
	
		
	}
	
	
	public void createOrUpdate(){
		incomeDao.createOrUpdate(incomeBean);
		
	}

	
	public void delete(){
		incomeDao.delete(incomeBean);
		
	}

	public IncomeBean getIncomeBean() {
		return incomeBean;
	}


	public void setIncomeBean(IncomeBean incomeBean) {
		this.incomeBean = incomeBean;
		if(incomeBean.getId()==-1){
			isNew = true;
		}
	}


	public boolean isNew() {
		return isNew;
	}


	public void setNew(boolean isNew) {
		this.isNew = isNew;
	}


	public List<CategoryBean> getListCategory() {
		return listCategory;
	}


	public void setListCategory(List<CategoryBean> listCategory) {
		this.listCategory = listCategory;
	}


	public void readCategory() {
		listCategory = categoryDao.readAll();
		
	}


	public void insertNewCategory(CategoryBean cB) {
		
		categoryDao.createOrUpdate(cB);
		
	}
	
	
	
}
